#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    string clearStars(string s) {
        vector<vector<int>> vec(26);
        for(int i=0;i<s.size();i++)
        {
            char ch=s[i];
            if(ch!='*')
            {
                vec[ch-'a'].push_back(i);
                continue;
            }
            for(auto& it:vec)
            {
                if(!it.empty()) 
                {
                    it.pop_back();
                    break;
                }
            }
        }
        vector<int> idx;
        for(auto&it:vec)
        {
            idx.insert(idx.end(),it.begin(),it.end());
        }
        sort(idx.begin(),idx.end());
        string ret;
        for(int i=0;i<idx.size();i++)
        {
            ret.push_back(s[idx[i]]);
        }
        return ret;
    }
};